import store from '@/store';
import Vue from 'vue';
import VueRouter, { Route, RouteConfig } from 'vue-router';

Vue.use(VueRouter);

const routes: Array<RouteConfig> = [
	{
		path: '/',
		name: 'Home',
		meta: {
			title: '赛事管理平台'
		},
		component: () => import('@/views/home/index.vue')
	},
	{
		path: '/pl',
		name: 'ProductList',
		meta: {
			title: '项目列表'
		},
		component: () => import('@/views/list/index.vue')
	},
	{
		path: '/pg',
		name: 'ProductGrade',
		meta: {
			title: '项目评分'
		},
		component: () => import('@/views/grade/index.vue'),
		beforeEnter: (to, from, next) => {
			if (store.state.user?.judgeId == '') {
				next('/');
				return;
			}
			next();
		}
	},
	{
		path: '*',
		redirect: '/'
	}
];

const router = new VueRouter({
	routes
});

router.beforeEach((to, from, next) => {
	if (to.meta.title) document.title = to.meta.title;
	next();
});

export default router;
